package com.ljx.recruitment.sale.controller;

import com.ljx.recruitment.common.domain.vo.resp.ApiResult;
import com.ljx.recruitment.common.domain.vo.resp.PageResp;
import com.ljx.recruitment.sale.domain.entity.TrialApplication;
import com.ljx.recruitment.sale.domain.vo.req.ProductTrialApplicationPageReq;
import com.ljx.recruitment.sale.domain.vo.req.ProductTrialApplicationSubmitReq;
import com.ljx.recruitment.sale.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "产品接口")
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;

    @ApiOperation("产品试用表申请")
    @PostMapping("/trial/application")
    public ApiResult<Void> submitTrialApplication(@RequestBody ProductTrialApplicationSubmitReq req) {
        productService.submitTrialApplication(req);
        return ApiResult.success();
    }

    @ApiOperation("管理员查询产品试用表申请分页")
    @GetMapping("/admin/trial/application/page")
    public ApiResult<PageResp<TrialApplication>> getTrialApplicationPage(ProductTrialApplicationPageReq req) {
        return ApiResult.success(productService.getTrialApplicationPage(req));
    }

    @ApiOperation("管理员更新产品试用表申请")
    @PostMapping("/admin/trial/application")
    public ApiResult<Void> adminSubmitTrialApplication(@RequestBody ProductTrialApplicationSubmitReq req) {
        productService.adminSubmitTrialApplication(req);
        return ApiResult.success();
    }

    @ApiOperation("查询产品试用申请")
    @GetMapping("/trial/application/{trialApplicationId}")
    public ApiResult<TrialApplication> getTrialApplication(@PathVariable("trialApplicationId") Long trialApplicationId) {
        return ApiResult.success(productService.getTrialApplication(trialApplicationId));
    }

}
